module.exports = {
  up: async (queryInterface) => {
    console.log('🧹 Removing old system:* permissions...');
    
    // 删除所有 resource 以 'system:' 开头的旧权限
    const result = await queryInterface.sequelize.query(`
      DELETE FROM permissions 
      WHERE resource LIKE 'system:%'
    `);
    
    console.log(`✅ Removed ${result[0].affectedRows || 0} old system:* permissions`);
    
    // 同时清理 role_permissions 表中可能引用了这些权限的记录
    await queryInterface.sequelize.query(`
      DELETE FROM role_permissions 
      WHERE permission_id NOT IN (SELECT id FROM permissions)
    `);
    
    console.log('✅ Cleaned up orphaned role_permissions records');
  },

  down: async () => {
    // 无法恢复已删除的数据
    console.log('⚠️  Cannot restore deleted permissions');
  },
};

